home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NotificationMon ƒ / NotificationMon.ƒ / Source / Event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-22  |  5.0 KB  |  240 lines  |  [TEXT/KAHL]

  1. /*
  2.     This file contains all the code needed to handle dispatching events.
  3.     Any files that need to access the globals should include the Event.h file.
  4. */
  5.  
  6. #include "Event.h"
  7. #include <AppleEvents.h>
  8. #include "NotificationMon.h"
  9.  
  10. Boolean        Done = false;
  11. Boolean        KeyPressed = false;
  12. char        KeyValue = 0;
  13. Boolean        InBackGround = false;
  14.  
  15. void DoCloseWindow(EventRecord *Event, WindowPtr theWindow)
  16. {
  17.     if(TrackGoAway(theWindow,Event->where))
  18.     {
  19.         CloseWindow(theWindow);
  20.     }
  21. }
  22.  
  23. void DoClickInContent(EventRecord *Event, WindowPtr theWindow)
  24. {
  25.     int                part;
  26.     ControlHandle    ctlh;
  27.     Point            pt;
  28.     GrafPtr            saveport;
  29.     Rect            frame;
  30.     
  31.     if(theWindow!=FrontWindow())
  32.     {
  33.         SelectWindow(theWindow);
  34.     }
  35.     else
  36.     {
  37.         GetPort(&saveport);
  38.         SetPort(theWindow);
  39.         if(IsNotificationDoc(theWindow))
  40.             NotificationClick(theWindow, Event);
  41.         SetPort(saveport);
  42.     }
  43. }
  44.  
  45.  
  46.  
  47.  
  48. void DoDragWindow(register EventRecord *Event, register WindowPtr theWindow)
  49. {
  50.     DragWindow(theWindow,Event->where,&screenBits.bounds);
  51. }
  52.  
  53.  
  54. void DoGrowWindow(register EventRecord *Event, register WindowPtr theWindow)
  55. {
  56.     long    newSize;
  57.     int        newHeight,newWidth;
  58.     GrafPtr    savePort;
  59.     
  60.     if(IsNotificationDoc(theWindow))
  61.         SizeNotificationWindow(theWindow,Event);
  62.     else {
  63.         GetPort(&savePort);
  64.         SetPort(theWindow);
  65.         newSize = GrowWindow(theWindow,Event->where,&screenBits.bounds);
  66.         newHeight = HiWord(newSize);
  67.         newWidth = LoWord(newSize);
  68.         SizeWindow(theWindow,newWidth,newHeight,true);
  69.         SetPort(savePort);
  70.     }
  71. }
  72.  
  73. DoZoom(register EventRecord *Event, register WindowPtr theWindow, int part)
  74. {
  75.     GrafPtr savePort;
  76.     
  77.     GetPort(&savePort);
  78.     SetPort(theWindow);
  79.     
  80.     if(TrackBox(theWindow,Event->where,part))
  81.     {
  82.         if(IsNotificationDoc(theWindow))
  83.             ZoomNotificationWindow(theWindow, part);
  84.         else
  85.             ZoomWindow(theWindow,part,true);
  86.     }
  87.     
  88.     SetPort(savePort);
  89. }
  90.  
  91.  
  92.  
  93. void DoMenu(register long msel)
  94. {
  95.     int item,menu;
  96.     item = LoWord(msel);
  97.     menu = HiWord(msel);
  98.     MenuDispatch(menu, item);
  99.     HiliteMenu(0);                        /* remove menu title hiliting */
  100. }
  101.  
  102. DoKey(EventRecord *Event)
  103. {
  104.     char        c;
  105.     
  106.     c = (char)Event->message & charCodeMask;
  107.     
  108.     if((Event->modifiers & cmdKey) == FALSE)
  109.     {
  110.         KeyPressed = true;
  111.         KeyValue = c;
  112.     }
  113.     else
  114.     {
  115.         DoMenu(MenuKey(Event->message & charCodeMask));    
  116.     }
  117. }
  118.  
  119. void DrawVerticalGrowIcon(WindowPtr theWindow)
  120. {
  121.     Rect        clip;
  122.  
  123.     clip = theWindow->portRect;
  124.     clip.left = clip.right - 15;
  125.     clip.top = clip.bottom - 15;
  126.     ClipRect(&clip);
  127.     
  128.     DrawGrowIcon(theWindow);
  129.     ClipRect(&theWindow->portRect);
  130. }
  131.  
  132. void DoUpdate(register EventRecord *Event)
  133. {
  134.     WindowPtr    theWindow;
  135.     GrafPtr        savePort;
  136.     
  137.     GetPort(&savePort);                            /* save current port */
  138.     
  139.     theWindow=(WindowPtr)Event->message;        /* get windowPtr from event msg */
  140.     SetPort(theWindow);
  141.     ClipRect(&theWindow->portRect);
  142.     BeginUpdate(theWindow);                        
  143.     EraseRect(&theWindow->portRect);            /* erase content region */
  144.  
  145.     DrawControls(theWindow);                    /* draw any controls in the window */
  146.     DrawVerticalGrowIcon(theWindow);
  147.     
  148.     DrawImage(theWindow);                        /* sample routine to draw contents */    
  149.  
  150.     
  151.     EndUpdate(theWindow);
  152.         
  153.     SetPort(savePort);
  154. }
  155.  
  156.  
  157.  
  158. void DoActivate(EventRecord *Event)
  159. {
  160.  
  161.     if(Event->modifiers & activeFlag)
  162.         if(IsNotificationDoc((WindowPeek)Event->message))
  163.             ActivateNotificationWindow(Event->message);
  164.     else
  165.         if(IsNotificationDoc((WindowPeek)Event->message))
  166.             DeactivateNotificationWindow(Event->message);
  167. }
  168.  
  169. void DoMFinder(register EventRecord *Event)
  170. {
  171.     if( (Event->message >> 24) == suspendResumeMessage) {
  172.         InBackGround = !(Event->message & resumeFlag);
  173.         NotificationDocLayerSwitch();
  174.     }
  175. }
  176.  
  177. void DoClick(EventRecord *Event)
  178. {
  179.     WindowPtr    theWindow;
  180.     switch(FindWindow(Event->where, &theWindow))
  181.     {
  182.         case inDesk:        break;
  183.         case inMenuBar:        DoMenu(MenuSelect(Event->where));
  184.                             break;
  185.         case inSysWindow:    SystemClick(Event,theWindow);
  186.                             break;
  187.         case inContent:        DoClickInContent(Event,theWindow);
  188.                             break;
  189.         case inDrag:        DoDragWindow(Event,theWindow);
  190.                             break;
  191.         case inGrow:        DoGrowWindow(Event,theWindow);
  192.                             break;
  193.         case inGoAway:        DoCloseWindow(Event,theWindow);
  194.                             break;
  195.         case inZoomIn:        DoZoom(Event,theWindow,inZoomIn);
  196.                             break;
  197.         case inZoomOut:        DoZoom(Event,theWindow,inZoomOut);
  198.                             break;
  199.     }
  200. }
  201.  
  202.  
  203.  
  204. void MainEvent(void)
  205. {
  206.     EventRecord    Event;
  207.     Boolean        anEvent;
  208.     
  209.     KeyPressed = false;                /* set to false every time through    */
  210.     
  211.     anEvent = WaitNextEvent(everyEvent,&Event,GetSleepTime(),nil);
  212.  
  213.     if(anEvent)
  214.     {
  215.         switch(Event.what)
  216.         {
  217.             case nullEvent:            CheckNotifications();        break;
  218.             case mouseDown:            DoClick(&Event);            break;
  219.             case mouseUp:                                         break;
  220.             case keyDown:            DoKey(&Event);                break;
  221.             case keyUp:                                             break;
  222.             case autoKey:            DoKey(&Event);                break;
  223.             case updateEvt:            DoUpdate(&Event);            break;
  224.             case diskEvt:                                         break;
  225.             case activateEvt:        DoActivate(&Event);            break;
  226.             case networkEvt:                                    break;
  227.             case driverEvt:                                         break;
  228.             case app1Evt:                                         break;
  229.             case app2Evt:                                         break;
  230.             case app3Evt:                                         break;
  231.             case osEvt:                DoMFinder(&Event);            break;
  232.             case kHighLevelEvent:    DoHighLevelEvent(&Event);    break;
  233.         }
  234.     }
  235.     else
  236.         CheckNotifications();
  237. }
  238.  
  239.  
  240.